<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo</title></title>
</head>
<body>
  <div id="root"></div>
  <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <script src="https://unpkg.com/prop-types@15.6/prop-types.js"></script>
  <script type="text/babel">

    class Person extends React.Component{
      // 生命周期
      state = {
        timer: null,
        opacity: 1
      }

      

      componentDidMount(){
        this.setState({
            timer: setInterval(()=>{
            if(this.state.opacity<=0){
              this.setState({
                opacity: 1
              })
            }else{
              this.setState({
                opacity: this.state.opacity - 0.1
              })
            }
          },200)
        })
      }

      componentWillUnmount(){
        clearInterval(this.state.timer)
      }
      

      death = ()=>{
        ReactDOM.unmountComponentAtNode(document.getElementById("root"));
      }

      render(){
        return (
          <div>
            <h1 style={{opacity: this.state.opacity}}>
              hello world
            </h1>
            <button onClick={this.death}>销毁</button>
          </div>
        )
      }
    }


    ReactDOM.render(<Person />,document.getElementById("root"))
  </script>
</body>
</html>